import 'dart:convert';
import 'dart:developer' as developer;

class LogUtil {

  static bool isLogEnable = false;

  static logJson(dynamic message, {tag = 'APP Log ==> '}) {
    log(message,formatJson: true,tag: tag);
  }

  static log(dynamic message, {formatJson = false,tag = 'APP Log ==> '}) {
    if (isLogEnable) {
      try {
        if (formatJson) {
          message = '\n${const JsonEncoder.withIndent('  ').convert(json.decode(message))}';
        }
      } catch (e) {}
      developer.log(message, name: tag);
    }
  }

  /// 打印错误日志，catch里面的，无论是否开启日志或者正式线都打印
  static logError(dynamic message, {tag = 'Error'}) {
    developer.log(message, name: tag);
  }
}